package cn.jett.domain.strategy.service.rule.tree.factory;

import cn.jett.domain.strategy.model.valobj.RuleTreeVO;
import cn.jett.domain.strategy.model.vo.RuleLogicCheckTypeVO;
import cn.jett.domain.strategy.service.rule.tree.ILogicTreeNode;
import cn.jett.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import cn.jett.domain.strategy.service.rule.tree.factory.engine.impl.DecisionTreeEngine;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author 战斗天使
 * @Description 规则树工厂
 * @Date 2024/6/20
 */
@Service
public class DefaultTreeFactory {

    private final Map<String, ILogicTreeNode> logicTreeNodeGroup;

    /**
     * 构造规则树节点集合
     * @param logicTreeNodeGroup
     */
    public DefaultTreeFactory(Map<String, ILogicTreeNode> logicTreeNodeGroup) {
        this.logicTreeNodeGroup = logicTreeNodeGroup;
    }

    /**
     * 提供规则树引擎
     * @param ruleTreeVO
     * @return
     */
    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO){
        return new DecisionTreeEngine(logicTreeNodeGroup, ruleTreeVO);
    }

    /**
     * 规则处理结果(处理状态、奖品信息)
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TreeActionEntity {
        /**
         * 处理状态
         */
        private RuleLogicCheckTypeVO ruleLogicCheckType;
        /**
         * 返回奖品信息
         */
        private StrategyAwardVO strategyAwardVO;
    }

    /**
     * 规则节点处理后返回的奖品信息
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StrategyAwardVO {
        /**
         * 抽奖奖品id - 内部流转使用
         */
        private Integer awardId;
        /**
         * 抽奖奖品规则
         */
        private String awardRuleValue;
    }
}
